
//
// Created by zhou on 2021/11/28.
//
#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
    int search(vector<int>& nums, int target) {
        int size=nums.size();
        int left=0;
        int right=size-1;
        int mid=(left+right)/2;
        while(left<=right){

            if(nums[mid]==target)return mid;
            else if(nums[mid]>nums[left]){
                if(target==nums[left])return left;
                else if(target>nums[left]&&target<nums[mid]){
                    right=mid-1;
                }
                else{
                    left=mid+1;
                }
            }
            else{
                if(target<nums[right]&&target>nums[mid]){
                    left=mid+1;
                }
                else if(target==nums[right])return right;
                else{
                    right=mid-1;
                }
            }
            mid=(left+right)/2;
        }
        if(nums[mid]==target)return mid;
        return -1;
    }
};
int main(){
    vector<int> ans={3,4,5,6,7,1,2};
    Solution solution;
    cout<<solution.search(ans,2);
}
